package com.lsy.weizhi2.customview;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.lsy.weizhi2.JsonObject.ActivityListObject;
import com.lsy.weizhi2.R;
import com.lsy.weizhi2.config.Constants;
import com.lsy.weizhi2.config.MyInfo;
import com.lsy.weizhi2.myutils.UserInfoCall;
import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.autolayout.utils.AutoLayoutHelper;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * Created by 嗨哟 on 2017/3/18.
 */
public class UserInfo extends AutoRelativeLayout {
    private Context context;
    private View view;
    private TextView user_name,user_hot,user_classify,user_summary,user_follow;
    private ImageView user_image;
    private UserInfoCall userInfoCall;
    public UserInfo(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        view = LayoutInflater.from(context).inflate(R.layout.user_info,this,true);
        AutoUtils.autoSize(view);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        user_name= (TextView) findViewById(R.id.user_name);
        user_hot= (TextView) findViewById(R.id.user_hot);
        user_classify= (TextView) findViewById(R.id.user_classify);
        user_summary= (TextView) findViewById(R.id.user_summary);
        user_follow= (TextView) findViewById(R.id.user_follow);
        user_image= (ImageView) findViewById(R.id.user_image);
        user_follow.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                userInfoCall.onClick(view,UserInfoCall.FOLLOW);
            }
        });
        user_image.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                userInfoCall.onClick(view,UserInfoCall.IMAGE);
            }
        });
    }

    public String getFollow(){
        String follow=user_follow.getText().toString().trim();
        return follow;
    }

    public void setFollow(String string){
        user_follow.setText(string);
    }

    public void setContent(String name,int image,String guanzhu){
        if(!TextUtils.isEmpty(name)){
            user_name.setText(name);
        }
            user_hot.setText("");
            user_classify.setText("情感达人");
            user_summary.setText("简介");
        if(guanzhu==null||guanzhu.length()==0){
            user_follow.setVisibility(View.GONE);
        }else{
            user_follow.setText(guanzhu);
        }
        Glide.with(context).load(new GlideUrl(Constants.DOWN_USER_PICTURE+image,new LazyHeaders.Builder().addHeader("WZ-AUTH-TOKEN", MyInfo.Token).addHeader("WZ-AUTH-ID",MyInfo.User_Id+"").build()))
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transform(new GlideCircleTransform(context))
                .error(R.mipmap.default_head)
                .into(user_image);

    }

    public void setUserInfoCall(UserInfoCall userInfoCall){
        this.userInfoCall=userInfoCall;
    }

    private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this);
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        if (!isInEditMode())
        {
            mHelper.adjustChildren();
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
